#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
int main()
{
    pid_t id = fork();
    if(id < 0)
    {
        perror("fork fail");
    }
    else if(id == 0)
    {
        while(1)
        {
            printf("i am child process\n");
            sleep(1);
        }
        exit(0);
    }
    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    if(rid < 0)
    {
        printf("没有需要等待的进程\n");
    }
    else 
    {
        if(WIFEXITED(status))
        {
            printf("正常退出退出码为%d\n",WEXITSTATUS(status));
        }
        else 
        {
            printf("异常退出，退出码为%d\n",status & 0xff);
        }
    }
 
 
     return 0;
}
